package jp.yvn.game.shooting.element;

import android.graphics.Canvas;
import android.graphics.Paint;

/**
 * The class that defines the FPS element
 * 
 * @author Yvn_pq
 */
public class FpsEntity {

	/** Paint setting */
	private final int FPS_COLOR = 0xff000000;

	private final int FPS_TEXT_SIZE = 20;

	private Paint mFpsPaint;

	/** Fps Element Point */
	private final int mX = 10;

	private final int mY = 20;

	/** The text to view */
	private String mFpsText = "0";

	private int mRenderingCnt;

	/** Time to start the count */
	private long mStartTime;

	/**
	 * Constructor
	 */
	public FpsEntity() {
		mStartTime = System.currentTimeMillis();
		mRenderingCnt = 0;
		mFpsPaint = new Paint();
		mFpsPaint.setColor(FPS_COLOR);
		mFpsPaint.setTextSize(FPS_TEXT_SIZE);
		mFpsPaint.setAntiAlias(true);
		mFpsPaint.setDither(false);
	}

	/**
	 * Update the FPS
	 * 
	 * @return String Fps
	 */
	public void updateFps() {
		// more than one second has elapsed
		if (999 < System.currentTimeMillis() - mStartTime) {
			mFpsText = String.valueOf(mRenderingCnt);
			mRenderingCnt = 0;
			mStartTime = System.currentTimeMillis();
		} else {
			mRenderingCnt++;
		}
	}

	/**
	 * draw
	 * 
	 * @param canvas
	 */
	public void draw(Canvas canvas) {
		canvas.drawText(mFpsText, mX, mY, mFpsPaint);
	}

	public Paint getPaint() {
		return mFpsPaint;
	}

	public void setPaint(Paint paint) {
		this.mFpsPaint = paint;
	}
}
